//
// Created by xbm on 23-3-6.
//
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include <vector>
#include <functional>
#include "timeit.h"
#include "log.h"


using namespace std;
using namespace chrono;
using namespace util;



void stressingTest(int times, LogLevel logLevel) {
    stringstream s;
    for (int i = 0; i < times; ++i) {
        s.str("");
        s << i << "  " << this_thread::get_id();
        log(s.view(), logLevel);
    }
}

void stressingSingleThread(int times) {
    cout << "----------------stressing single test begin-----------\n";
    cout << "data size is " << times << endl;
    time_it(stressingTest, times, LogLevel::MESSAGE);
    cout << "----------------stressing single test end-----------" << endl;
}

void stressingMultiThread(int times,int threads_num){
    cout<<"----------------stressing multi test begin-----------\n";
    cout<<"data size is "<<times<<endl;
    cout<<"thread num is "<<threads_num<<endl;
    vector<thread>vec;
    for(int i=0;i<threads_num;++i){
        vec.emplace_back([=]() { time_it(stressingTest, times, static_cast<LogLevel>(i)); });
    }
    for(int i=0;i<threads_num;++i){
        vec[i].join();
    }
    cout << "----------------stressing multi test end-----------" << endl;

}



int main() {
    stressingSingleThread(10000);
    stressingSingleThread(100000);
    stressingSingleThread(1000000);

    stressingMultiThread(10000, 2);
    stressingMultiThread(100000, 2);
    stressingMultiThread(1000000, 2);

    stressingMultiThread(10000, 4);
    stressingMultiThread(100000, 4);
    stressingMultiThread(1000000, 4);

}